package es.ats.codington.web.servlets;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import es.ats.codington.festival.domain.Visitor;
import es.ats.codington.festival.services.VisitorServiceImpl;

/**
 * Servlet implementation class ListAllVisitorsServlets.
 */
@WebServlet("/ListAllVisitorsServlets")
public class ListAllVisitorsServlets extends HttpServlet {
	
	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = 1L;
       
    /**
     * Instantiates a new list all visitors servlets.
     *
     * @see HttpServlet#HttpServlet()
     */
    public ListAllVisitorsServlets() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * Do get.
	 *
	 * @param request the request
	 * @param response the response
	 * @throws ServletException the servlet exception
	 * @throws IOException Signals that an I/O exception has occurred.
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession(true);
	   	try{		
			VisitorServiceImpl vis = new VisitorServiceImpl();
			ArrayList<Visitor> visitors = new ArrayList<Visitor>();				
			visitors = vis.searchAllVisitors();
			session.setAttribute("AllVisitors", visitors);
			RequestDispatcher rd=request.getRequestDispatcher("ListVisitors.jsp");  
	        rd.include(request,response); 
	    }catch(Exception theException){
	        System.out.println(theException); 
	   }
	}

	/**
	 * Do post.
	 *
	 * @param request the request
	 * @param response the response
	 * @throws ServletException the servlet exception
	 * @throws IOException Signals that an I/O exception has occurred.
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	   	 //TODO : Method
	}

}
